home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / WINDOWS / ODBTN.ARJ / TEST.C < prev    next >
C/C++ Source or Header  |  1992-07-06  |  11KB  |  257 lines

  1. /******************************************************************************************************
  2. *                                                                                                     *
  3. *                                      TEST.C                                                          *
  4. *                        OWNERDRAW BUTTON DLL TEST APPLICATION                                        *
  5. *                                    by Ted Ott                                                       *
  6. *                                                                                                     *
  7. *                                                                                                     *
  8. ******************************************************************************************************/
  9.  
  10. #include <windows.h>
  11. #include "test.h"
  12.  
  13.  
  14. /***************************************procs*********************************************************/
  15.  
  16. long FAR PASCAL WndProc                 (HWND, WORD, WORD, LONG);       //main body
  17. /////////////////////////////////////////////////////
  18. //        .DLL functions
  19. /////////////////////////////////////////////////////
  20. int FAR PASCAL CreateButtons (int BtnIDStart, int BtnIDEnd, HWND hwnd, LONG lParam);
  21. int FAR PASCAL DrawButtons (HWND hwnd, LONG lParam);
  22. int FAR PASCAL DeleteBtnBitMaps (int BtnIDStart, int BtnIDEnd);
  23. int FAR PASCAL InitializeButtons (int BtnIDStart, int BtnIDEnd,
  24.                   int BtnWidth, int BtnHeight,
  25.                   int BtnXStartPos, int BtnYStartPos,
  26.                   int BtnXPosIncrement, int BtnYPosIncrement,
  27.                   HANDLE hinst);
  28.  
  29. /**********************************global variables***************************************************/
  30.  
  31. char szAppName []                       = "test";                       //app name
  32. HANDLE hInst;                                                           //app instance
  33.  
  34. /******************************************************************************************************
  35. *                                 WinMain entrypoint                                                  *
  36. ******************************************************************************************************/
  37.  
  38. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  39.                    LPSTR lpszCmdLine, int nCmdShow)
  40. {
  41.     HWND hwnd;                                                      //window identifier
  42.     MSG  msg;                                                       //message identifier
  43.     WNDCLASS wndclass;                                              //window class
  44.  
  45.  
  46.     hInst = hInstance;                                              //app instance
  47.  
  48.     if (!hPrevInstance)
  49.     {
  50.         wndclass.style           =CS_HREDRAW | CS_VREDRAW ;
  51.         wndclass.lpfnWndProc     =(WNDPROC)WndProc ;
  52.                 wndclass.cbClsExtra      =0 ;
  53.                 wndclass.cbWndExtra      =0 ;
  54.                 wndclass.hInstance       =hInstance ;
  55.         wndclass.hIcon           =LoadIcon (hInstance, szAppName) ;
  56.                 wndclass.hCursor         =LoadCursor (NULL, IDC_ARROW) ;
  57.                 wndclass.hbrBackground   =GetStockObject (WHITE_BRUSH) ;
  58.         wndclass.lpszMenuName    =szAppName ;
  59.         wndclass.lpszClassName   =szAppName ;
  60.  
  61.         RegisterClass (&wndclass);
  62.  
  63.  
  64.  
  65.     }
  66.  
  67. ////////////////////////////////////////////////////////////////////////////////////////////////
  68. //This function initializes buttons to be used as a button bar in the main window
  69. //The first two parameters specify the first two buttons used in the application
  70. //        (a loop in .Dll is used to initialize them: for(i=0;i<2;i++))
  71. //The second two parameters specify the height and width of the bitmaps used
  72. //The next two specify the upper left X & Y position of the first button
  73. //The next two specify X & Y position increments of buttons
  74. //The last parameter specifies instance of app that contains button bitmaps (located in .RC)
  75. //wndproc will do the work of displaying the buttons
  76. //////////////////////////////////////////////////////////////////////////////////////////////// 
  77.  
  78.     InitializeButtons (0, 2, 28, 28, 0, 0, 28, 0, hInst);
  79.  
  80.     hwnd = CreateWindow (szAppName, "Test",
  81.                  WS_OVERLAPPEDWINDOW,
  82.                  CW_USEDEFAULT, CW_USEDEFAULT,
  83.                  CW_USEDEFAULT, CW_USEDEFAULT,                  //intro bitmap size
  84.                  NULL, NULL, hInstance, NULL);
  85.  
  86.  
  87.     ShowWindow (hwnd, nCmdShow);
  88.     UpdateWindow (hwnd);
  89.         
  90.         while (GetMessage (&msg, NULL, 0,0))
  91.     {
  92.         TranslateMessage (&msg);
  93.         DispatchMessage (&msg);
  94.     }
  95.  
  96.  
  97.  
  98.     return msg.wParam;
  99. }
  100. /**********************************************************************************************************
  101. *                     TestOne dialog box                                                               *
  102. **********************************************************************************************************/
  103.  
  104. BOOL FAR PASCAL TestOneProc (HWND hDlg, WORD message, WORD wParam, LONG lParam)
  105. {
  106.     switch (message)
  107.         {
  108.                 case WM_INITDIALOG:
  109. ////////////////////////////////////////////////////////////////////////
  110. //Initialize next two buttons to use in this dialog box
  111. //Use the .RC to create the child windows (dialog boxes only)
  112. ////////////////////////////////////////////////////////////////////////
  113.             InitializeButtons (2, 4, 28, 28, 132, 52, 28, 0,
  114.                     GetWindowWord (hDlg, GWW_HINSTANCE));
  115.             return FALSE;
  116.         case WM_DRAWITEM:
  117. ///////////////////////////////////////////////////////////////////////
  118. //Used to draw the buttons when nessasary
  119. ///////////////////////////////////////////////////////////////////////
  120.             DrawButtons (hDlg, lParam);
  121.             return 0;
  122.         case WM_COMMAND:
  123.         {
  124.             switch (wParam)
  125.                         {
  126.                 case IDM_BUTTON_THREE:
  127.                     MessageBox (hDlg, "button 3", "test", MB_OK);
  128.                     return 0;
  129.                 case IDM_BUTTON_FOUR:
  130.                     MessageBox (hDlg, "button 4", "test", MB_OK);
  131.                     return 0;
  132.                                case IDOK:
  133. ///////////////////////////////////////////////////////////////////////
  134. //Delete the bitmaps for buttons created above. VERY IMPORTANT!
  135. ///////////////////////////////////////////////////////////////////////
  136.                     DeleteBtnBitMaps (2, 4);
  137.                                     EndDialog (hDlg, 0);
  138.                     return TRUE;
  139.                         }
  140.         }
  141.     }
  142.         return FALSE;
  143. }
  144. /**********************************************************************************************************
  145. *                     TestTwo dialog box                                                               *
  146. **********************************************************************************************************/
  147.  
  148. #pragma argsused
  149.  
  150. BOOL FAR PASCAL TestTwoProc (HWND hDlg, WORD message, WORD wParam, LONG lParam)
  151. {
  152.     switch (message)
  153.         {
  154.                 case WM_INITDIALOG:
  155. //////////////////////////////////////////////////////////////////////
  156. //To use several X & Y positons that can not be incremented,
  157. //initialize seperately with different values
  158. //////////////////////////////////////////////////////////////////////
  159.             InitializeButtons (4, 6, 28, 28, 0, 0, 28, 0,
  160.                     GetWindowWord (hDlg, GWW_HINSTANCE));
  161.             InitializeButtons (6, 7, 28, 28, 132, 52, 28, 0,
  162.                     GetWindowWord (hDlg, GWW_HINSTANCE));
  163.             return FALSE;
  164.         case WM_DRAWITEM:
  165. ///////////////////////////////////////////////////////////////////////
  166. //Used to draw the buttons when nessasary
  167. ///////////////////////////////////////////////////////////////////////
  168.             DrawButtons (hDlg, lParam);
  169.             return 0;
  170.         case WM_COMMAND:
  171.         {
  172.             switch (wParam)
  173.                         {
  174.                 case IDM_BUTTON_FIVE:
  175.                     MessageBox (hDlg, "button 5", "test", MB_OK);
  176.                     return 0;
  177.                 case IDM_BUTTON_SIX:
  178.                     MessageBox (hDlg, "button 6", "test", MB_OK);
  179.                     return 0;
  180.                 case IDM_BUTTON_SEV:
  181.                     MessageBox (hDlg, "button 7", "test", MB_OK);
  182.                     return 0;
  183.                                case IDOK:
  184. ///////////////////////////////////////////////////////////////////////
  185. //Delete the bitmaps for buttons created above. VERY IMPORTANT!
  186. ///////////////////////////////////////////////////////////////////////
  187.                     DeleteBtnBitMaps (4, 7);
  188.                                     EndDialog (hDlg, 0);
  189.                     return TRUE;
  190.                         }
  191.         }
  192.     }
  193.         return FALSE;
  194. }
  195.  
  196.  
  197. /******************************************************************************************************
  198. *                                  base procedure                                                     *
  199. ******************************************************************************************************/
  200.  
  201.  
  202. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  203. {
  204.     static HANDLE   hInstance;                                      //app instance
  205.     static FARPROC  lpfnTestOneProc;
  206.     static FARPROC  lpfnTestTwoProc;
  207.  
  208.     switch (message)
  209.                 {
  210.                 case WM_CREATE:
  211.             hInstance       = ((LPCREATESTRUCT) lParam)->hInstance;
  212.             lpfnTestOneProc    = MakeProcInstance (TestOneProc, hInstance);
  213.             lpfnTestTwoProc    = MakeProcInstance (TestTwoProc, hInstance);
  214. ////////////////////////////////////////////////////////////////////////
  215. //This function creates the child windows in the main window
  216. //for the buttons initialized in WinMain. (Do not used this
  217. //function for dialog boxes, use CONTROL statements in .RC instead)
  218. //////////////////////////////////////////////////////////////////////// 
  219.             CreateButtons (0, 2, hwnd, lParam);
  220.             return 0;
  221.          case WM_DRAWITEM:
  222. ///////////////////////////////////////////////////////////////////////
  223. //draws buttons when needed
  224. ///////////////////////////////////////////////////////////////////////
  225.             DrawButtons (hwnd, lParam);
  226.             return 0;
  227.          case WM_COMMAND:
  228.             switch (wParam)
  229.                         {
  230.                 case IDM_TEST1:                                //displays about box
  231.                     DialogBox (hInstance, "TestBoxOne", hwnd, lpfnTestOneProc);
  232.                     return 0;
  233.                 case IDM_TEST2:                                //displays about box
  234.                     DialogBox (hInstance, "TestBoxTwo", hwnd, lpfnTestTwoProc);
  235.                     return 0;
  236.                       case IDM_BUTTON_ONE:
  237.                     MessageBox (hwnd, "button 1", "test", MB_OK);
  238.                     return 0;
  239.                 case IDM_BUTTON_TWO:
  240.                     MessageBox (hwnd, "button 2", "test", MB_OK);
  241.                     return 0;
  242.             }
  243.             break;
  244.                 case WM_DESTROY:
  245. //////////////////////////////////////////////////////////////////////
  246. //Deletes bitmaps. VERY IMPORTANT!
  247. //////////////////////////////////////////////////////////////////////
  248.             DeleteBtnBitMaps (0, 2);
  249.             PostQuitMessage (0);
  250.             return 0;
  251.                 }
  252.  
  253.  
  254.     return DefWindowProc (hwnd, message, wParam, lParam);
  255. }
  256.  
  257.